import { Request } from "@/plugins/request";
import type { SvgCaptchaInter, LoginInter, LoginForm, UserInfo, Role } from "@/typings/api";
import type { Permission } from "@/typings/permission";
import type { PageRequest } from "@/util/page-request";

const request = new Request();

/** 获取验证码 */
export const getSvgCaptcha = () => {
  return request.get<SvgCaptchaInter>("auth/captcha");
};

/** 用户登录 */
export const userLogin = (data: LoginForm) => {
  return request.post<LoginInter>("auth/login", data);
};

/** 获取权限树 */
export const getPermissions = () => {
  return request.get<Permission[]>("permission/tree");
};

/** 退出登录 */
export const userLogout = () => {
  return request.get<null>("auth/logout");
};

/** 查询用户 */
export const getUsers = (pageRequest: PageRequest) => {
  return request.post<UserInfo[]>("user/getUsers", pageRequest);
};

/** 获取所有角色 */
export const getRoles = () => {
  return request.get<Role[]>("role/getRoles");
};

/** 添加用户 */
export const addUser = (createUserModel: any) => {
  return request.post<any>("role/addUser", createUserModel);
};
